<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<div class="aui-text-desc aui-gutter-column-lg">
  {{ 'protection_big_data_register_tip_label' | i18n }}
</div>
<lv-form [formGroup]="formGroup" class="formGroup">
  <lv-form-item>
    <lv-form-label lvRequired>
      {{ 'common_name_label' | i18n }}
    </lv-form-label>
    <lv-form-control [lvErrorTip]="nameErrorTip">
      <input lv-input type="text" formControlName="name" />
    </lv-form-control>
  </lv-form-item>
  <lv-form-item>
    <lv-form-label lvRequired>
      {{ 'protection_server_ip_label' | i18n }}
      <i
        lv-icon="aui-icon-help"
        lv-tooltip="{{ 'protection_es_ip_tips_label' | i18n }}"
        lvTooltipTheme="light"
        class="configform-constraint"
        lvColorState="true"
      ></i>
    </lv-form-label>
    <lv-form-control [lvErrorTip]="serverErrorTip">
      <input lv-input type="text" formControlName="serverLink" />
    </lv-form-control>
  </lv-form-item>
  <lv-form-item>
    <lv-form-label lvRequired>
      {{ 'protection_auth_mode_label' | i18n }}
    </lv-form-label>
    <lv-form-control [lvErrorTip]="baseUtilService.requiredErrorTip">
      <lv-select
        formControlName="loginMode"
        [lvOptions]="authOptions"
        lvValueKey="value"
      >
      </lv-select>
    </lv-form-control>
  </lv-form-item>
  <ng-container
    *ngIf="clusterAuthType.kerberos.value === formGroup.value.loginMode"
  >
    <lv-form-item>
      <lv-form-label lvRequired>
        Kerberos
        <i
          lv-icon="aui-icon-help"
          lv-tooltip="{{
            'protection_hdfs_register_cluster_kerberos_tip_label' | i18n
          }}"
          lvTooltipTheme="light"
          class="configform-constraint"
          lvColorState="true"
        ></i>
      </lv-form-label>
      <lv-form-control [lvErrorTip]="baseUtilService.requiredErrorTip">
        <lv-group lvGutter="8px">
          <lv-select
            formControlName="kerberosId"
            [lvOptions]="kerberosOptions"
            lvValueKey="kerberosId"
            lvShowFilter
            lvFilterKey="label"
            lvFilterMode="contains"
          >
          </lv-select>
          <button
            lv-button
            (click)="createKerberos()"
            pmpermission
            pmOperation="CreateKerberos"
          >
            {{ 'common_create_label' | i18n }}
          </button>
        </lv-group>
      </lv-form-control>
    </lv-form-item>
    <lv-form-item>
      <lv-form-label>
        {{ 'insight_certificate_label' | i18n }}
        <i
          lv-icon="aui-icon-help"
          lv-tooltip="{{
            'protection_es_kerberos_certificate_tips_label' | i18n
          }}"
          lvTooltipTheme="light"
          class="configform-constraint"
          lvColorState="true"
        ></i>
      </lv-form-label>
      <lv-form-control>
        <lv-upload
          lvAccept=".crt"
          lvShowUpload="false"
          (lvFilesChange)="filesChange($event, 'cert')"
          [lvFilters]="fileFilters"
        ></lv-upload>
      </lv-form-control>
    </lv-form-item>
  </ng-container>
  <ng-container
    *ngIf="clusterAuthType.system.value === formGroup.value.loginMode"
  >
    <lv-form-item>
      <lv-form-label>
        {{ 'common_username_label' | i18n }}
        <i
          lv-icon="aui-icon-help"
          lv-tooltip="{{ 'protection_register_cluster_user_tip_label' | i18n }}"
          lvTooltipTheme="light"
          class="configform-constraint"
          lvColorState="true"
        ></i>
      </lv-form-label>
      <lv-form-control [lvErrorTip]="nameErrorTip">
        <input lv-input type="text" formControlName="username" />
      </lv-form-control>
    </lv-form-item>
    <lv-form-item>
      <lv-form-label>
        {{ 'common_password_label' | i18n }}
        <i
          lv-icon="aui-icon-help"
          lv-tooltip="{{ 'protection_register_cluster_user_tip_label' | i18n }}"
          lvTooltipTheme="light"
          class="configform-constraint"
          lvColorState="true"
        ></i>
      </lv-form-label>
      <lv-form-control [lvErrorTip]="passwordErrorTip">
        <aui-inupt-with-eye formControlName="password"></aui-inupt-with-eye>
      </lv-form-control>
    </lv-form-item>
  </ng-container>
  <lv-form-item>
    <lv-form-label lvRequired>
      {{ 'protection_proxy_host_label' | i18n }}
    </lv-form-label>
    <lv-form-control>
      <aui-agent-select
        [lvOptions]="proxyHostOptions"
        formControlName="agents"
        lvValueKey="value"
        lvMode="multiple"
        [isAgent]="false"
      ></aui-agent-select>
      <span class="aui-text-desc">
        {{ 'protection_es_host_tips_label' | i18n }}
      </span>
    </lv-form-control>
  </lv-form-item>
  <lv-form-item>
    <lv-form-label lvRequired>
      {{ 'protection_warehouser_path_user_label' | i18n }}
      <i
        lv-icon="aui-icon-help"
        lv-tooltip="{{ 'protection_warehouser_path_user_tips_label' | i18n }}"
        lvTooltipTheme="light"
        class="configform-constraint"
        lvColorState="true"
      ></i>
    </lv-form-label>
    <lv-form-control [lvErrorTip]="pathErrorTip">
      <input lv-input type="text" formControlName="pathUser" />
    </lv-form-control>
  </lv-form-item>
  <lv-form-item>
    <lv-form-label lvRequired>
      {{ 'protection_warehouser_path_user_attr_label' | i18n }}
      <i
        lv-icon="aui-icon-help"
        lv-tooltip="{{
          'protection_warehouser_path_user_attr_tips_label' | i18n
        }}"
        lvTooltipTheme="light"
        class="configform-constraint"
        lvColorState="true"
      ></i>
    </lv-form-label>
    <lv-form-control [lvErrorTip]="pathErrorTip">
      <input lv-input type="text" formControlName="pathAttr" />
    </lv-form-control>
  </lv-form-item>
  <ng-container
    *ngIf="clusterAuthType.kerberos.value === formGroup.value.loginMode"
  >
    <lv-form-item>
      <lv-form-label>
        {{ 'protection_enbale_security_protocol_label' | i18n }}
      </lv-form-label>
      <lv-form-control>
        <lv-switch formControlName="useSecProtocols"></lv-switch>
        <div style="width: 460px;" *ngIf="!formGroup?.value.useSecProtocols">
          <i
            style="display: inline-block; margin-right: 4px;"
            lv-icon="lv-icon-status-info"
            lvColorState="true"
            class="type-icon"
          ></i>
          <span class="form-tips aui-text-desc">
            {{ 'protection_hive_cert_tips_label' | i18n }}
          </span>
        </div>
      </lv-form-control>
    </lv-form-item>
    <lv-form-item>
      <lv-form-label>
        {{ 'protection_enable_security_aigorithm_label' | i18n }}
      </lv-form-label>
      <lv-form-control>
        <lv-switch formControlName="useSecCipherSuites"></lv-switch>
        <div style="width: 460px;" *ngIf="!formGroup?.value.useSecCipherSuites">
          <i
            style="display: inline-block; margin-right: 4px;"
            lv-icon="lv-icon-status-info"
            lvColorState="true"
            class="type-icon"
          ></i>
          <span class="form-tips aui-text-desc">
            {{ 'protection_hive_cert_tips_label' | i18n }}
          </span>
        </div>
      </lv-form-control>
    </lv-form-item>
  </ng-container>
</lv-form>

<ng-template #modalFooter>
  <div class="lv-modal-btns">
    <lv-group lvGutter="14px">
      <button
        lv-button
        lvType="primary"
        (click)="test()"
        [disabled]="!enableBtn"
        [lvLoading]="testLoading"
      >
        {{ 'common_test_label' | i18n }}
      </button>
      <button
        lv-button
        lvType="primary"
        (click)="ok()"
        [disabled]="!isTest || !enableBtn"
        [lvLoading]="okLoading"
      >
        {{ 'common_ok_label' | i18n }}
      </button>
      <button lv-button (click)="cancle()">
        {{ 'common_cancel_label' | i18n }}
      </button>
    </lv-group>
  </div>
</ng-template>
